import { MenuItemDefinition, Types } from '@amcax/base';
import { ctx2 } from '@app-cad/module';
import { HookAPI } from 'antd/es/modal/useModal';
import { ProductTreeNode } from '../../types';

export const removeReference: MenuItemDefinition<ProductTreeNode> = {
  id: 'remove-reference',
  children: '移除',
  hidden: ({ props: { type } }) => {
    return !([Types.PLANE, Types.FRAME] as string[]).includes(type);
  },
  onClick: async ({ data, props: doc }) => {
    const confirmed = await (data.modal as HookAPI).confirm({
      closable: true,
      title: `移除${doc.type === Types.FRAME ? '坐标系' : '平面'}`,
      content: `确认移除 ${doc.title} 吗？`,
      okText: '移除',
      okType: 'danger',
      cancelText: '取消',
    });

    if (confirmed) {
      await ctx2.commandCenters.basicCommands.deleteObjects([doc.key]);
    }
  },
};
